package com.gupaoedu.demo.socket;

import java.io.*;
import java.net.Socket;

/**
 * <p>
 *
 * </p>
 *
 * @author Nicky
 * @since 2019-07-19
 */
public class ClientSocketDemo {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("localhost",8080);
            PrintWriter printWriter = new PrintWriter(socket.getOutputStream(),true);
            //从控制台拿到数据
            BufferedReader sin = new BufferedReader(new InputStreamReader(System.in));
            //输入流
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String line = sin.readLine();
            while (!line.equals("bye")){
                printWriter.println(line);

                System.out.println("Server: "+ bufferedReader.readLine());

                line = sin.readLine();

            }
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
